import java.util.Scanner;

class Student {
    String name;
    String id;
    String course;
    int score;
}

class SimpleStudentScoreSystem {
    private static final int MAX_STUDENTS = 100;
    private static Student[] students = new Student[MAX_STUDENTS];
    private static int studentCount = 0;

    private static void addScore() {
        if (studentCount >= MAX_STUDENTS) {
            System.out.println("存储已满！");
            return;
        }

        @SuppressWarnings("resource")
        Scanner scanner = new Scanner(System.in);
        System.out.println("\n--- 记录学生成绩 ---");
        System.out.print("姓名: ");
        String name = scanner.nextLine();
        System.out.print("学号: ");
        String id = scanner.nextLine();
        System.out.print("课程: ");
        String course = scanner.nextLine();
        System.out.print("分数(0-100): ");
        int score = scanner.nextInt();

        students[studentCount] = new Student();
        students[studentCount].name = name;
        students[studentCount].id = id;
        students[studentCount].course = course;
        students[studentCount].score = score;
        studentCount++;
        System.out.println("记录成功！");
    }

    private static void queryScore() {
        @SuppressWarnings("resource")
        Scanner scanner = new Scanner(System.in);
        System.out.println("\n--- 查询学生成绩 ---");
        System.out.println("1. 按学生姓名查询");
        System.out.println("2. 按学生学号查询");
        System.out.println("3. 按课程名称查询");
        System.out.print("请输入选项序号: ");
        int choice = scanner.nextInt();
        scanner.nextLine();

        System.out.print("请输入查询关键字: ");
        String keyword = scanner.nextLine();
        boolean found = false;

        for (int i = 0; i < studentCount; i++) {
            boolean match = false;
            switch (choice) {
                case 1:
                    match = students[i].name.equals(keyword);
                    break;
                case 2:
                    match = students[i].id.equals(keyword);
                    break;
                case 3:
                    match = students[i].course.equals(keyword);
                    break;
                default:
                    System.out.println("无效选项！");
                    return;
            }
            if (match) {
                System.out.printf("姓名: %s, 学号: %s, 课程: %s, 成绩: %.1f\n",
                        students[i].name, students[i].id, 
                        students[i].course, (float)students[i].score);
                found = true;
            }
        }
        if (!found) {
            System.out.println("未找到记录！");
        }
    }

    private static void calculateStatistics() {
        @SuppressWarnings("resource")
        Scanner scanner = new Scanner(System.in);
        System.out.println("\n--- 统计课程成绩 ---");
        System.out.print("请输入课程名称: ");
        String course = scanner.nextLine();

        int sum = 0, count = 0, max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
        for (int i = 0; i < studentCount; i++) {
            if (students[i].course.equals(course)) {
                sum += students[i].score;
                count++;
                max = Math.max(max, students[i].score);
                min = Math.min(min, students[i].score);
            }
        }

        if (count == 0) {
            System.out.println("该课程无记录！");
            return;
        }

        System.out.printf("课程: %s\n平均分: %.2f\n最高分: %.1f\n最低分: %.1f\n",
                course, (float)sum/count, (float)max, (float)min);
    }

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("\n=================================");
            System.out.println("欢迎进入学生成绩管理系统");
            System.out.println("=================================");
            System.out.println("请选择操作：");
            System.out.println("1. 记录成绩");
            System.out.println("2. 查询成绩");
            System.out.println("3. 统计课程成绩");
            System.out.println("4. 退出系统");
            System.out.print("请输入选项: ");
            int choice = scanner.nextInt();
            scanner.nextLine();

            switch (choice) {
                case 1:
                    addScore();
                    break;
                case 2:
                    queryScore();
                    break;
                case 3:
                    calculateStatistics();
                    break;
                case 4:
                    System.out.println("感谢使用学生成绩管理系统，再见！");
                    return;
                default:
                    System.out.println("无效选项！");
            }
        }
    }
}